package com.silverhaze.diamond.client.ui.table.renderers;

import com.silverhaze.diamond.client.ui.table.model.ServiceTableModel;
import com.silverhaze.diamond.client.ui.table.shells.ServiceShell;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;

/**
 * SystemUser: Babanin
 * Date: 20.07.2008
 * Time: 2:36:52
 */
public class ServiceTableRenderer extends DefaultTableCellRenderer {
    // implements javax.swing.table.TableCellRenderer
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

        JLabel superComponent = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

        if (value instanceof ServiceShell) {
            ServiceShell shell = (ServiceShell) value;

            superComponent.setText(shell.getValue().toString());
            superComponent.setToolTipText(shell.getToolTipText());
//            superComponent.setFont(superComponent.getFont().deriveFont(Font.BOLD));

            if (column == ServiceTableModel.OWNER_ROW || column == ServiceTableModel.DETAIL) {
                superComponent.setHorizontalAlignment(SwingConstants.LEFT);
                superComponent.setText(" " + getText());
            } else {
                superComponent.setHorizontalAlignment(SwingConstants.CENTER);
            }


            if (!isSelected) {
                superComponent.setBackground(Color.WHITE);
//                    if (shell.isComplete()) {
//                        if (row % 2 == 0) {
//                            superComponent.setForeground(Color.GREEN.darker().darker().darker());
//                        } else {
//                            superComponent.setForeground(Color.GREEN.darker().darker().darker());
//                        }
//                    } else {
//                        if (row % 2 == 0) {
//                            superComponent.setForeground(Color.RED.darker());
//                        } else {
//                            superComponent.setForeground(Color.RED.darker());
//                        }
//                    }
            //    superComponent.setForeground(Color.BLACK);
            }

        } else {
            superComponent.setText(value.toString());
        }

        return superComponent;
    }
}

